package com.zh;
import java.io.*;
/**
 * @description:
 * @author: zhangHang
 * @date: Created in 2020/3/29 9:46
 * @version: 1.0
 * @modified By:
 */
public class ImportData {
    static StudentSet studentSet=new StudentSet();
    FileInputStream fis=null;
    InputStreamReader isr=null;
    BufferedReader br=null;
    public StudentSet importDataFromTxtFile(String filePath){
        try {
            studentSet.students.clear();
            String strInputLine="";
            String str1="";
            fis =new FileInputStream(filePath);
            isr = new InputStreamReader(fis);
            br=new BufferedReader(isr);
            while ((strInputLine=br.readLine()) != null) {
                String[] items=strInputLine.split("\t");
                StudentRecord studentRecord=new StudentRecord();
                studentRecord.setA(items[0]);
                studentRecord.setB(items[1]);
                studentRecord.setC(items[2]);
                studentRecord.setD(items[3]);
                studentRecord.setE(items[4]);

                studentSet.add(studentRecord);
            }

        } catch (FileNotFoundException e) {
            System.out.println("找不到指定文件");
        } catch (IOException e) {
            System.out.println("读取文件是失败");
        } finally{
            try{
                assert br !=null;
                br.close();
                isr.close();
                fis.close();
            }catch (IOException e){
                e.printStackTrace();
            }
        }
        return studentSet;
    }

}
